local QI = DailyIntake.QuestItems;
local Localize = DailyIntake.Localize;

--------------------------------------------------------------------------------
-- Knight of Ebon Blade quest items
--------------------------------------------------------------------------------

-- Add item: Ebon Blade Banner; http://www.wowhead.com/?item=42480
local function EbonBladeBanner()
    return not UnitOnTaxi("player")

        -- target must be dead
        and UnitIsDead("target")

        -- must not be tapped by other players
        and not QI.UnitIsTappedByOtherPlayer("target")

        -- must not have completed quest objective yet
        and not QI.QuestObjectiveIsDone(12995, 1)

        -- must target one of the following:
        and (QI.UnitIsEntity("target", 29880, QI.Entity.Mob) -- Jotunheim Warrior; http://www.wowhead.com/?npc=29880
          or QI.UnitIsEntity("target", 30037, QI.Entity.Mob) -- Mjordin Combatant; http://www.wowhead.com/?npc=30037
          or QI.UnitIsEntity("target", 30243, QI.Entity.Mob) -- Njorndar Spear-Sister; http://www.wowhead.com/?npc=30243
          or QI.UnitIsEntity("target", 30632, QI.Entity.Mob) -- Mjordin Water Magus; http://www.wowhead.com/?npc=30632
          or QI.UnitIsEntity("target", 30250, QI.Entity.Mob) -- Valhalas Vargul; http://www.wowhead.com/?npc=30250
          );

end;
QI.RegisterQuestItem(42480, QI.Priority.Normal, EbonBladeBanner);

-- Add item: Bone Gryphon; http://www.wowhead.com/?item=40600
local function BoneGryphon()
    return not UnitOnTaxi("player")

        -- must not have completed quest objective yet
        and not QI.QuestObjectiveIsDone(12815, 1)

        -- must be in Icecrown
        and GetZoneText() == Localize("Icecrown")

        -- must be in Onslaught Harbor
        and GetSubZoneText() == Localize("Onslaught Harbor");
end;
QI.RegisterQuestItem(40600, QI.Priority.Lower, BoneGryphon);

-- Add item: Darkmender's Tincture; http://www.wowhead.com/?item=40587
local function DarkmendersTincture()
    return not UnitOnTaxi("player")

        -- must be in Icecrown
        and GetZoneText() == Localize("Icecrown")

        -- must be in Onslaught Harbor
        and GetSubZoneText() == Localize("Onslaught Harbor")

        -- must target a dead unit
        and UnitIsDead("target")

        -- must not be tapped by other players
        and not QI.UnitIsTappedByOtherPlayer("target");
end;
QI.RegisterQuestItem(40587, QI.Priority.Normal, DarkmendersTincture);

-- Add item: Abomination Reanimation Kit; http://www.wowhead.com/?item=43968
local function AbominationReanimationKit()
    -- this item is used for two quests, both have same objectives, but have different IDs
    -- because one is for Horde and the other is for Alliance
    local questId = 13276; -- horde quest id
    local englishFaction, _ = UnitFactionGroup("player");
    if englishFaction == "Alliance" then
        questId = 13289;
    end;

    return not UnitOnTaxi("player")
        -- must be in Icecrown
        and GetZoneText() == Localize("Icecrown")

        -- must have reagent: Chilled Abomination Guts; http://www.wowhead.com/?item=43966
        and GetItemCount(43966) > 0

        -- must not have completed the quest yet
        and (not QI.QuestObjectiveIsDone(questId, 1)
          or not QI.QuestObjectiveIsDone(questId, 2)
          or not QI.QuestObjectiveIsDone(questId, 3)
          );
end;
QI.RegisterQuestItem(43968, QI.Priority.Normal, AbominationReanimationKit);

-- Add item: Orb of Illusion; http://www.wowhead.com/?item=44246
local function OrbOfIllusion()
    -- this item is used for two quests, both have same objectives, but have different IDs
    -- because one is for Horde and the other is for Alliance
    local questId = 13353; -- horde quest id
    local englishFaction, _ = UnitFactionGroup("player");
    if englishFaction == "Alliance" then
        questId = 13323;
    end;

    return not UnitOnTaxi("player")
        -- must be in Icecrown
        and GetZoneText() == Localize("Icecrown")

        -- must target Dark Subjugator; http://www.wowhead.com/?npc=32236
        and QI.UnitIsEntity("target", 32236, QI.Entity.Mob)

        -- must not be tapped by other players
        and not QI.UnitIsTappedByOtherPlayer("target")

        -- must not have completed the quest yet
        and not QI.QuestObjectiveIsDone(questId, 1);
end;
QI.RegisterQuestItem(44246, QI.Priority.Normal, OrbOfIllusion);

-- Add item: SGM-3; http://www.wowhead.com/?item=44212
local function SGM_3()

    -- there will be two versions of the same item use
    -- 1) Skybreaker Recon Fighte is targeted - then use the item on target
    -- 2) No unit is targeted - then attenpt to use the item with Skybreaker Recon Fighte as a target

    -- check common conditions for both cases
    if not UnitOnTaxi("player")
        -- must be in Icecrown
        and GetZoneText() == Localize("Icecrown")

        -- must be in propper area
        and QI.PlayerIsInArea(0.36, 0.46, 0.48, 0.53)

        -- must not have completed the quest yet
        and not QI.QuestObjectiveIsDone(13331, 1)
    then
        -- case 1
        if UnitExists("target") then
            if
                -- must target Skybreaker Recon Fighte; http://www.wowhead.com/?npc=32189
                QI.UnitIsEntity("target", 32189, QI.Entity.Vehicle)

                -- target myst be alive
                and not UnitIsDead("target")

                -- must not be tapped by other players
                and not QI.UnitIsTappedByOtherPlayer("target")
            then
                return true;
            end;

        -- case 2
        else
            return true, "#showtooltip item:44212\n/run DailyIntake.QuestItems.DisableMacroRefresh();\n/target [nodead] " .. Localize("Skybreaker Recon Fighte") .. "\n/use [nodead] item:44212\n/cleartarget\n/run DailyIntake.QuestItems.EnableMacroRefresh();";
        end;
    end;
end;
QI.RegisterQuestItem(44212, QI.Priority.Normal, SGM_3);

-- Add item: Dart Gun; http://www.wowhead.com/?item=44222
local function DartGun()

    -- there will be two versions of the same item use
    -- 1) Orgrim's Hammer Scout is targeted - then use the item on target
    -- 2) No unit is targeted - then attenpt to use the item with Orgrim's Hammer Scout as a target

    -- check common conditions for both cases
    if not UnitOnTaxi("player")
        -- must be in Icecrown
        and GetZoneText() == Localize("Icecrown")

        -- must be in propper area
        and QI.PlayerIsInArea(0.47, 0.38, 0.62, 0.49)

        -- must not have completed the quest yet
        and not QI.QuestObjectiveIsDone(13333, 1)
    then
        -- case 1
        if UnitExists("target") then
            if
                -- must target Orgrim's Hammer Scout; http://www.wowhead.com/?npc=32201
                QI.UnitIsEntity("target", 32201, QI.Entity.Mob)

                -- target myst be alive
                and not UnitIsDead("target")

                -- must not be tapped by other players
                and not QI.UnitIsTappedByOtherPlayer("target")
            then
                return true;
            end;

        -- case 2
        else
            return true, "#showtooltip item:44222\n/run DailyIntake.QuestItems.DisableMacroRefresh();\n/target [nodead] " .. Localize("Orgrim's Hammer Scout") .. "\n/cast [nodead] item:44222\n/cleartarget\n/run DailyIntake.QuestItems.EnableMacroRefresh();";
        end;
    end;
end;
QI.RegisterQuestItem(44222, QI.Priority.Normal, DartGun);

-- Add item: Flesh Giant Spine; http://www.wowhead.com/?item=44009
local function FleshGiantSpine()
    return not UnitOnTaxi("player")

        -- must not have Pustulant Spinal Fluid in inventory
        and GetItemCount(44010) == 0

        -- must not have completed the quest aleady
        and not (QI.QuestObjectiveIsDone(13281, 1) or QI.QuestObjectiveIsDone(13297, 1));
end;
QI.RegisterQuestItem(44009, QI.Priority.Low, FleshGiantSpine);

-- Add item: Pustulant Spinal Fluid; http://www.wowhead.com/?item=44010
local function PustulantSpinalFluid()
    return not UnitOnTaxi("player")

        -- must be in propper area
        and QI.PlayerIsInArea(0.62750327587128, 0.60813647508621, 0.64240771532059, 0.62357956171036)

        -- must not have completed the quest aleady
        and not (QI.QuestObjectiveIsDone(13281, 1) or QI.QuestObjectiveIsDone(13297, 1));
end;
QI.RegisterQuestItem(44010, QI.Priority.Normal, PustulantSpinalFluid);

-- Add item: Rod of Siphoning; http://www.wowhead.com/?item=44433
local function RodOfSiphoning()
    return not UnitOnTaxi("player")

        -- must be in propper area
        and QI.PlayerIsInArea(0.27, 0.54, 0.32, 0.57)

        -- must have less than 5 x Dark Matter in inventory
        and GetItemCount(44434) < 5

        -- must not have completed the quest aleady
        and not (QI.QuestObjectiveIsDone(13365, 1) or QI.QuestObjectiveIsDone(13344, 1));
end;
QI.RegisterQuestItem(44433, QI.Priority.Normal, RodOfSiphoning);

-- Add item: Copperclaw's Volatile Oil; http://www.wowhead.com/?item=43608
-- Add item: Smuggled Solution; http://www.wowhead.com/?item=44048
local function VolatilitySolution()
    return not UnitOnTaxi("player")

        -- must be in propper area
        and GetSubZoneText() == Localize("Broken Front")

        -- must have at least one of each: Abandoned Armor, Pile of Bones, Abandoned Helm
        and GetItemCount(43616) > 0
        and GetItemCount(43609) > 0
        and GetItemCount(43610) > 0

        -- must not have completed the quest aleady
        and not (QI.QuestObjectiveIsDone(13292, 1) or QI.QuestObjectiveIsDone(13261, 1));
end;
QI.RegisterQuestItem(43608, QI.Priority.Normal, VolatilitySolution);
QI.RegisterQuestItem(44048, QI.Priority.Normal, VolatilitySolution);

-- Add item: Diluted Cult Tonic; http://www.wowhead.com/?item=44307
local function DilutedCultTonic()
    return not UnitOnTaxi("player")

    -- must be in Icecrown
    and GetZoneText() == Localize("Icecrown")

    -- number of Tainted Essence must be less than 10
    and GetItemCount(44301) < 10

    -- number of Writhing Mass must be less than 1
    and GetItemCount(44304) < 1

    -- must not have completed quest yet
    and not (QI.QuestObjectiveIsDone(13322, 1) or QI.QuestObjectiveIsDone(13357, 1));
end;
QI.RegisterQuestItem(44307, QI.Priority.Low, DilutedCultTonic);

-- Add item: Tainted Essence; http://www.wowhead.com/?item=44301
local function TaintedEssence()
    return not UnitOnTaxi("player")

    -- must be in Icecrown
    and GetZoneText() == Localize("Icecrown")

    -- must have 10 x Tainted Essence in inventory
    and GetItemCount(44301) == 10

    -- number of Writhing Mass must be less than 1
    and GetItemCount(44304) < 1

    -- must not have completed quest yet
    and not (QI.QuestObjectiveIsDone(13322, 1) or QI.QuestObjectiveIsDone(13357, 1));
end;
QI.RegisterQuestItem(44301, QI.Priority.Low, TaintedEssence);

-- Add item: Writhing Mass; http://www.wowhead.com/?item=44304
local function WrithingMass()
    return not UnitOnTaxi("player")

    -- must be in Icecrown
    and GetZoneText() == Localize("Icecrown")

    -- must be at one of the couldrons
    and (QI.PlayerIsCloseTo(0.48941525816917, 0.33199819922447, 0.0015)
        or QI.PlayerIsCloseTo(0.49064746499062, 0.34182468056679, 0.0015)
        or QI.PlayerIsCloseTo(0.49675241112709, 0.34379041194916, 0.0015)
        )

    -- must not have completed quest yet
    and not (QI.QuestObjectiveIsDone(13322, 1) or QI.QuestObjectiveIsDone(13357, 1));
end;
QI.RegisterQuestItem(44304, QI.Priority.Normal, WrithingMass);

-- =============================================================
-- Added by LaoTseu
-- =============================================================

-- Add item: Confessor's Prayer Book; http://www.wowhead.com/?item=46870
local function ConfessorPrayerBook()
    return not UnitOnTaxi("player")

    -- must be in Hrothgar's Landing
    and GetZoneText() == "Hrothgar's Landing"

	 -- must target Slain Tualiq Villager; http://www.wowhead.com/?npc=34852
	 and QI.UnitIsEntity("target", 34852, QI.Entity.Mob)

	 -- must not have completed quest objective yet
	 -- Alliance and Horde have a different version of this quest
	 and (   (UnitFactionGroup("player") == "Alliance" and not QI.QuestIsDone(14077))
	 	   or (UnitFactionGroup("player") == "Horde"    and not QI.QuestIsDone(14144)));

end;
QI.RegisterQuestItem(46870, QI.Priority.Normal, ConfessorPrayerBook);


-- Add item: Kvaldir War Horn; http://www.wowhead.com/?item=47006
local function KvaldirWarHorn()
    return not UnitOnTaxi("player")

   -- must be in Hrothgar's Landing
   and GetZoneText() == "Hrothgar's Landing"

	-- Need to be at a specific spot
	and QI.PlayerIsCloseTo(0.506, 0.154, 0.004)

	-- must not have completed quest objective yet
	and  not QI.QuestIsDone(14101);

end;
QI.RegisterQuestItem(47006, QI.Priority.Normal, KvaldirWarHorn);

-- Add item: Light-Blessed Relic; http://www.wowhead.com/?item=47033
local function LightBlessedRelic()
    return not UnitOnTaxi("player")

   -- must be in Hrothgar's Landing
   and GetZoneText() == Localize("Icecrown")

   -- must have Discarded Soul Crystal
   and GetItemCount(47035) > 0

   -- must target Fallen Hero's Spiritssss
   and QI.UnitIsEntity("target", 38144, QI.Entity.Mob)

	-- must not have completed quest objective yet
	and  not QI.QuestIsDone(14107);

end;
QI.RegisterQuestItem(47033, QI.Priority.Normal, LightBlessedRelic);

-- Add item: Mistcaller's Charm; http://www.wowhead.com/?item=47009
QI.RegisterQuestItem(47009, QI.Priority.Normal, function()
	return not UnitOnTaxi("player")

	-- must be in the cave
	and GetZoneText() == "Mistcaller's Cave"

	-- must not have completed quest objective yet
	-- http://www.wowhead.com/?quest=14102
	and  not QI.QuestIsDone(14102);

end);

-- Add item: Flaming Spears; http://www.wowhead.com/?item=46954
QI.RegisterQuestItem(46954, QI.Priority.Normal, function()
	-- This is a bit of a hack since this work only because the only
	-- taxi flying in Hrothgar's Landing is for this quest
	return UnitOnTaxi("player")

	-- must be in Hrothgar's Landing
	and GetZoneText() == "Hrothgar's Landing";

end);

-- Add item: Fresh Chum; http://www.wowhead.com/?item=47036
QI.RegisterQuestItem(47036, QI.Priority.Normal, function()
	return not UnitOnTaxi("player")

	-- must be in Icrecrow or near a boat
	and (GetZoneText() == Localize("Icecrown") or
	     GetZoneText() == "The Silver Blade" or		-- Alliance boat
	     GetZoneText() == "The Crimson Dawn")			-- Horde boat

	-- Need to be near one of the boats
	and (   (UnitFactionGroup("player") == "Alliance" and QI.PlayerIsCloseTo(0.669, 0.080, 0.04))
		  or (UnitFactionGroup("player") == "Horde"    and QI.PlayerIsCloseTo(0.742, 0.099, 0.04)))

	-- must not have completed quest objective yet
	-- Alliance and Horde have a different version of this quest
	-- http://www.wowhead.com/?quest=14112
	-- http://www.wowhead.com/?quest=14145
	and (   (UnitFactionGroup("player") == "Alliance" and not QI.QuestIsDone(14112))
		  or (UnitFactionGroup("player") == "Horde"    and not QI.QuestIsDone(14145)));
end);

-- 47029 -- "Bor's Fury"
-- Add item: Captured Kvaldir Banner; http://www.wowhead.com/?item=47029
QI.RegisterQuestItem(47029, QI.Priority.Normal, function()
	return not UnitOnTaxi("player")

	-- must be in Bor's Fury boat
	and GetZoneText() == "Bor's Fury";

end);

-- Add item: Kraken Tooth; http://www.wowhead.com/?item=46955
QI.RegisterQuestItem(46955, QI.Priority.Low, function()
	return not QI.QuestIsDone(14095);

end);
